package com.sky.task;

import com.sky.entity.Orders;
import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class OrderStatusTask {
    @Autowired
    private OrderMapper orderMapper;

    @Scheduled(cron = "0 0/1 * * * ?")
    public void changeOrderNotPay() {
        //查询时间是十五分钟之前,状态是未支付的订单
        Orders order = Orders.builder()
                .status(Orders.CANCELLED)
                .cancelTime(LocalDateTime.now())
                .cancelReason("订单超时").build();
        Integer integer = orderMapper.changeOrderNotPay(order);

        log.info("{}个订单已超时", integer);
    }

    @Scheduled(cron = " 0 0 1 * * ? ")
   // @Scheduled(cron = "0 0/1 * * * ?")
    public void changeOrders() {
        Integer integer = orderMapper.changeOrders();
        log.info("{}个订单忘记确认",integer);
    }
}
